import java.util.List;
import java.util.ArrayList;

public class Contract {

	/*estados: 
	 *0: waiting to send out contract
	 *1: Contract has been sent out
	 *2: Bids have been received
	 *3: Bids have been processed and best bid chosen
	 *4: Contract complete verified
	 * 
	 * */
	private Proposal m_proposal;
	private int m_state;
	private ArrayList<Bid> m_bids;
	private Player m_player;
	
	public Contract(Player jugador, Proposal proposal  )
	{
		m_state = 0;
		m_player = jugador;
		m_proposal = proposal;
	
	}
	
	public void SendOut()
	{
		//Send contract out to all agents
		m_state = 1;
		m_player.say(String.valueOf( m_proposal.GetSerializedProposal() ) ); 
		
			
	}
	
	public void SetBids(ArrayList<Bid> bids )
	{
		m_bids = bids;
		m_state = 2;
		
	}
	
	private void ReplyToBid(int bidIndex)
	{
		//Send reply to best bid
		
	}
	
	public void ProcessBids()
	{
		int bestBidIndex = 0;
		for(int i = 1; i < m_bids.size(); ++i)
		{
			//Check each bid and compare to best bid
			//if(m_bids[bestBidIndex] > m_bids[i])
				bestBidIndex = i;
		}
		
		ReplyToBid(bestBidIndex);
		m_state = 3;
	}
}
